<template>
  <div class="warp-box clearfix">
    <div class="warp-con">
      <div class="header">
        <div class="headerWrapper">
          <div class="search">
            <el-form :inline="true" class="demo-form-inline">
              <el-form-item>
                <el-input placeholder="物种名称" v-model="searchForm.name" clearable />
              </el-form-item>
              <el-form-item>
                <el-date-picker v-model="searchForm.createDate" type="daterange" range-separator="至" start-placeholder="开始日期"
                  end-placeholder="结束日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd">
                </el-date-picker>
              </el-form-item>
              <el-form-item>
                <el-input placeholder="测定人员" v-model="searchForm.personnel" clearable />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" class="upload" @click="query">查询</el-button>
                <el-button type="primary" class="upload" @click="addDialog" v-if="addBtn">新增</el-button>
              </el-form-item>
              <el-form-item>
                <!-- <el-button type="primary" @click="dialogImportVisible = true">导入</el-button>-->
                <!-- <el-button type="primary" class="upload" style="width: 112px" @click="exportPoint">导出</el-button>-->
              </el-form-item>
            </el-form>
          </div>
        </div>
      </div>
      <div class="content">
        <el-table ref="multipleTable" border stripe :data="tableData" v-loading="loading" element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)" style="width: 100%"
          class="tableLine" :max-height="635">
          <el-table-column prop="name" show-overflow-tooltip label="物种名称" align="center" />
          <el-table-column prop="oneName" show-overflow-tooltip label="保存库名称" align="center" />
          <el-table-column prop="twoName" show-overflow-tooltip label="保存区名称" align="center" />
          <el-table-column prop="threeName" show-overflow-tooltip label="树种分区" align="center" />
          <el-table-column prop="fourName" show-overflow-tooltip label="小区" align="center" />
          <el-table-column prop="specificName" show-overflow-tooltip label="种名" align="center" />
          <el-table-column prop="familyName" show-overflow-tooltip label="科名" align="center" />
          <el-table-column prop="germplasmType" show-overflow-tooltip label="种质名称" align="center" />
          <el-table-column prop="personnel" show-overflow-tooltip label="测定人员" align="center" />
          <el-table-column prop="determinationTime" show-overflow-tooltip label="测定日期" align="center" />
          <el-table-column fixed="right" label="操作" align="center" width="200">
            <template slot-scope="scope">
              <span class="pointer" @click="read(scope.row)">查看</span>
              <span v-if="updateBtn" class="pointer" @click="updateDialog(scope.row)"><i class="line"></i>修改</span>
              <span v-if="deleteBtn" class="pointer" @click="remove(scope.row)"><i class="line"></i>删除</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="paging">
        <el-pagination :page-size="this.pageSize" :page-sizes="[10,20,50]" :total="tableDataTotalCount" @current-change="handleCurrentChange"
                       @size-change="handleSizeChange" background layout="total, sizes, prev, pager, next, jumper" />
      </div>
    </div>
    <el-dialog :title="formTitle" :close-on-click-modal="false" :before-close="cancel" :visible.sync="dialogFormVisible">
      <el-form :model="addForm" :rules="rules" ref="ruleForm" label-width="160px" class="demo-ruleForm">
        <div class="form-table">
          <table>
            <tr>
              <td class="form-item_label">物种名称</td>
              <td>
                <el-select filterable v-model="addForm.name" @change="speciesChange" clearable :disabled="disabled">
                  <el-option v-for="(item, i) in species" :label="item.speciesName" :value="item.speciesName" :key="i" />
                </el-select>
              </td>
              <td>定值年份</td>
              <td>
                <el-date-picker v-model="addForm.decideYear" type="year" value-format="yyyy" placeholder="选择年份"
                  :disabled="disabled" />
              </td>
            </tr>
            <tr>
              <td>种名( 中文、拉丁 )</td>
              <td>
                <el-input class="td-input oblique" v-model="addForm.specificName" :disabled="disabled" />
              </td>
              <td>科名( 中文、拉丁 )</td>
              <td>
                <el-input class="td-input oblique" v-model="addForm.familyName" :disabled="disabled" />
              </td>
            </tr>
            <tr>
              <td class="form-item_label">保存库</td>
              <td>
                <el-select filterable v-model="addForm.oneId" @change="selectedOne" clearable :disabled="disabled">
                  <el-option v-for="(item, i) in oneData" :label="item.name" :value="item.id" :key="i" />
                </el-select>
              </td>
              <td class="form-item_label">保存区</td>
              <td>
                <el-select filterable v-model="addForm.twoId" @change="selectedTwo" clearable :disabled="disabled">
                  <el-option v-for="(item, i) in twoData" :label="item.name" :value="item.id" :key="i" />
                </el-select>
              </td>
            </tr>
            <tr>
              <td class="form-item_label">树种分区</td>
              <td>
                <el-select filterable v-model="addForm.threeId" @change="selectedThree" clearable :disabled="disabled">
                  <el-option v-for="(item, i) in threeData" :label="item.name" :value="item.id" :key="i" />
                </el-select>
              </td>
              <td class="form-item_label">小区</td>
              <td>
                <el-select filterable v-model="addForm.fourId" clearable :disabled="disabled">
                  <el-option v-for="(item, i) in fourData" :label="item.name" :value="item.id" :key="i" />
                </el-select>
              </td>
            </tr>
            <tr>
              <td>种质名称</td>
              <td>
                <el-select filterable v-model="addForm.germplasmName" @change="germplasmChange" :disabled="disabled">
                  <el-option v-for="item in registerPreservation" :key="item.id" :label="item.name" :value="item.id" />
                </el-select>
              </td>
              <td>保存种质类型</td>
              <td>
                <el-select multiple filterable allow-create default-first-option v-model="addForm.germplasmType"
                  clearable :disabled="disabled">
                  <el-option v-for="(item, i) in germplasm" :key="i" :label="item" :value="item" />
                </el-select>
              </td>
            </tr>
            <tr>
              <td>用途</td>
              <td>
                <el-select v-model="addForm.purpose" clearable filterable allow-create default-first-option placeholder="请选择或输入"
                  :disabled="disabled">
                  <el-option v-for="(item, i) in purpose" :key="i" :label="item" :value="item" />
                </el-select>
              </td>
              <td>植株编号</td>
              <td>
                <el-input class="td-input" readonly v-model="addForm.resourceNumber" @focus="numberClick" :disabled="disabled" />
              </td>
            </tr>
            <tr>
              <td>保存时间</td>
              <td>
                <el-date-picker type="date" placeholder="选择日期" value-format="yyyy-MM-dd" v-model="addForm.saveTime"
                  :disabled="disabled" />
              </td>
              <td>库中位置</td>
              <td>
                <div class="td3-box">
                  <LonLat ref="lonRef" @child-event="lonEvent" class="coordinate-type" v-if ="isReady" placeholder="经度" :msg-val="chilLon" :disabled="disabled"/>
                  <LonLat ref="latRef" @child-event="latEvent" class="coordinate-type"  v-if ="isReady" placeholder="纬度"  :msg-val="chilLat" :disabled="disabled"/>
                  <el-input v-model="addForm.alt" class="coordinate-type" placeholder="海拔" :disabled="disabled"/>
                </div>
                <!-- <el-input v-model="addForm.lon" placeholder="经度" class="coordinate" :disabled="disabled" />
                <span>-</span>
                <el-input v-model="addForm.lat" placeholder="纬度" class="coordinate" :disabled="disabled" />
                <span>-</span>
                <el-input v-model="addForm.alt" placeholder="海拔" class="coordinate" :disabled="disabled" /> -->
              </td>
            </tr>
            <tr>
              <td>繁殖方式</td>
              <td>
                <el-input class="td-input" v-model="addForm.breedMode" :disabled="disabled" />
              </td>
              <td>苗龄</td>
              <td>
                <el-input class="td-input" v-model="addForm.stockAge" :disabled="disabled" />
              </td>
            </tr>
            <tr>
              <td>平均树高(m)</td>
              <td>
                <el-input class="td-input" v-model="addForm.avgHigh" :disabled="disabled" />
              </td>
              <td>平均胸径(cm)</td>
              <td>
                <el-input class="td-input" v-model="addForm.avgDbh" :disabled="disabled" />
              </td>
            </tr>
            <tr>
              <td>平均冠幅(m,东西)</td>
              <td>
                <el-input class="td-input" v-model="addForm.avgPew" :disabled="disabled" />
              </td>
              <td>平均冠幅(m,南北)</td>
              <td>
                <el-input class="td-input" v-model="addForm.avgPsn" :disabled="disabled" />
              </td>
            </tr>
            <tr>
              <td style="display:table-cell;vertical-align:middle">生产及经济性状评价</td>
              <td colspan="3">
                <el-input type="textarea" v-model="addForm.productionEvaluate" :disabled="disabled" />
              </td>
            </tr>
            <tr>
              <td style="display:table-cell;vertical-align:middle">生长及抗逆性评价</td>
              <td colspan="3">
                <el-input type="textarea" v-model="addForm.growEvaluate" :disabled="disabled" />
              </td>
            </tr>
            <tr>
              <td>特殊性状</td>
              <td>
                <el-input class="td-input" v-model="addForm.specialCharacters" :disabled="disabled" />
              </td>
              <td style="display:table-cell; vertical-align:middle">综合评价</td>
              <td>
                <el-select filterable v-model="addForm.comprehensiveAssessment" clearable :disabled="disabled">
                  <el-option v-for="(item, i) in composite" :label="item" :value="item" :key="i" />
                </el-select>
              </td>
            </tr>
            <tr>
              <td>测定人员</td>
              <td>
                <el-input class="td-input" v-model="addForm.personnel" :disabled="disabled" />
              </td>
              <td>测定时间</td>
              <td>
                <el-date-picker type="date" placeholder="选择日期" value-format="yyyy-MM-dd" v-model="addForm.determinationTime"
                  :disabled="disabled" />
              </td>
            </tr>
            <tr>
              <td style="display:table-cell;vertical-align:middle">备注</td>
              <td colspan="3">
                <el-input type="textarea" v-model="addForm.remark" :disabled="disabled" />
              </td>
            </tr>
          </table>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button v-if="formEdit !== 'read'" type="primary" @click="saveData" class="dialogBtn">保 存</el-button>
        <el-button type="primary" @click="cancel" class="dialogBtn">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog title="调查数据" :close-on-click-modal="false" :width="'70%'" :before-close="cancelR" :visible.sync="dialogVisible">
      <el-table ref="resourceTable" border stripe :data="resourceTable" style="width: 100%" @select="handleSelection"
        @select-all="handleSelectionAll" @selection-change="selectionChange" class="tableLine">
        <el-table-column type="selection" align="center" width="55">
        </el-table-column>
        <el-table-column prop="createDate" show-overflow-tooltip label="创建时间" align="center">
        </el-table-column>
        <el-table-column prop="createName" show-overflow-tooltip label="创建人" align="center">
        </el-table-column>
        <el-table-column prop="number" show-overflow-tooltip label="植株编号" align="center">
        </el-table-column>
        <el-table-column prop="lon" show-overflow-tooltip label="经度" align="center">
        </el-table-column>
        <el-table-column prop="lat" show-overflow-tooltip label="纬度" align="center">
        </el-table-column>
        <el-table-column prop="alt" show-overflow-tooltip label="海拔" align="center">
        </el-table-column>
        <el-table-column prop="type" show-overflow-tooltip label="种质分类" align="center">
        </el-table-column>
        <el-table-column prop="zheight" show-overflow-tooltip label="树高(m)" align="center">
        </el-table-column>
        <el-table-column prop="dbh" show-overflow-tooltip label="胸径(cm)" align="center">
        </el-table-column>
        <el-table-column prop="pew" show-overflow-tooltip label="冠幅(m,东西)" align="center">
        </el-table-column>
        <el-table-column prop="psn" show-overflow-tooltip label="冠幅(m,南北)" align="center">
        </el-table-column>
      </el-table>
      <div class="paging">
        <el-pagination :page-size="this.pageSizeR" :page-sizes="[5, 10]" :total="resourceTotalCount" @current-change="handleCurrentChangeR"
                       @size-change="handleSizeChangeR" background layout="total, sizes, prev, pager, next, jumper">
        </el-pagination>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="getNumber" class="dialogBtn">确 定</el-button>
        <el-button type="primary" @click="cancelR" class="dialogBtn">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog title="导入测定评价" :visible.sync="dialogImportVisible" width="30%">
      <el-form :inline="true" class="demo-form-inline">
        <el-form-item>
          <el-upload class="file-uploader" name="file" :action="fileDomain" :show-file-list="false" :on-success="handleFileSuccess"
            :before-upload="beforeFileUpload" with-credentials :headers="upHeader">
            <el-button type="primary" class="upload" style="width: 112px">
              选取文件
            </el-button>
          </el-upload>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" class="upload" style="width: 112px" @click="downFileTemp">
            下载模板
          </el-button>
        </el-form-item>
        <div slot="tip" class="el-upload__tip">只能上传xls/xlsx文件，且不超过10MB</div>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
  import resourceApi from '@/api/resourceApi'
  import ResourceManageApi from '../../../api/ResourceManageApi'
  import LonLat from '../../../components/LatLon'

  export default {
    name: 'evaluate',
    components: {
      LonLat
    },
    data() {
      return {
        loading: false,
        fileDomain: process.env.SURVEY_DOMAIN + '/gr/resourceEvaluate/importExcel',
        dataError: '',
        upHeader: {
          token: `${window.localStorage.token}`
        },
        searchForm: {
          name: null,
          createDate: null,
          personnel: null
        },
        pageIndex: 1,
        pageSize: 10,
        totalCount: 0,
        tableData: [],
        addForm: {},
        formEdit: null,
        formTitle: null,
        species: [],
        number: [],
        pageIndexR: 1,
        pageSizeR: 10,
        resourceTable: [],
        resourceCount: 0,
        multipleSelection: [],
        purpose: ['用材', '生态', '经济林木', '木本花卉', '藤本植物'],
        dialogFormVisible: false,
        dialogVisible: false,
        dialogImportVisible: false,
        rules: {
          name: [{
            required: true,
            message: '物种名称不能为空',
            trigger: 'blur'
          }]
        },
        composite: ['好', '较好', '一般', '较差', '差'],
        germplasm: ['种源', '优树无性系', '半同胞家系', '全同胞家系', '选育无性系（杂交种）', '品种（系）', '地方（农家）品种', '其他'],
        registerPreservation: [],
        oneData: [],
        twoData: [],
        threeData: [],
        fourData: [],
        speciesMap: {},
        disabled: false,
        addBtn: false,
        updateBtn: false,
        deleteBtn: false,
        chilLon:'',
        chilLat:'',
        isReady:false
      }
    },
    computed: {
      tableDataTotalCount() {
        return this.totalCount ? this.totalCount : 0
      },
      resourceTotalCount() {
        return this.resourceCount ? this.resourceCount : 0
      }
    },
    created() {
      this.initBtn();
      this.getSpecies();
      this.findPageData();
      this.getRegisterPreservation();
    },
    methods: {

      //经度
      lonEvent(val) {
        this.addForm.lon = val;
      },

      latEvent(val) {
        this.addForm.lat = val;
      },
      downFileTemp() {
        resourceApi.getExcelTempFileEvaludate()
      },
      exportPoint() {
        resourceApi.exportExcelEvaluate()
      },
      beforeFileUpload(file) {
        let filename = file.name
        let size = file.size / 1024 / 1024
        if (filename.lastIndexOf('.') > 0) {
          let filehz = filename.substring(filename.lastIndexOf('.') + 1)
          let standbyList = ['xls', 'xlsx']
          if (standbyList.indexOf(filehz) !== -1) {
            if (size < 100) {
              return true
            } else {
              this.$notify({
                title: '消息',
                message: ('上传文件不能超过100M'),
                position: 'bottom-right',
                showClose: false,
                type: 'warning'
              })
              return false
            }
          } else {
            this.$notify({
              title: '消息',
              message: ('上传失败，请上传xls, xlsx文件'),
              position: 'bottom-right',
              showClose: false,
              type: 'warning'
            })
            return false
          }
        }
      },
      handleFileSuccess(res, file, fileList) {
        let Data = res
        if (Data.messageType === '0') {
          this.$notify({
            title: '消息',
            message: Data.Message || '操作成功',
            position: 'bottom-right',
            showClose: false,
            type: 'success'
          })
          this.dataError = ''
          // 这里需要返回table 解析后的数据
          this.tableData = Data.result || []
          this.loading = true
          this.findPageData()
        } else {
          this.dataError = Data.message
          this.$notify.error({
            title: '消息',
            position: 'bottom-right',
            message: this.dataError
          })
        }
      },
      selectionChange(val) {
        if (val.length > 0) {
          let avgHigh = 0
          let avgDbh = 0
          let avgPew = 0
          let avgPsn = 0
          for (let i = 0; i < val.length; i++) {
            avgHigh += parseInt(val[i].zheight ? val[i].zheight : 0)
            avgDbh += parseInt(val[i].dbh ? val[i].dbh : 0)
            avgPew += parseInt(val[i].pew ? val[i].pew : 0)
            avgPsn += parseInt(val[i].psn ? val[i].psn : 0)
          }
          avgHigh = avgHigh / val.length
          avgDbh = avgDbh / val.length
          avgPew = avgPew / val.length
          avgPsn = avgPsn / val.length
          this.addForm.avgHigh = avgHigh
          this.addForm.avgDbh = avgDbh
          this.addForm.avgPew = avgPew
          this.addForm.avgPsn = avgPsn
        }
      },
      query() {
        this.pageIndex = 1;
        this.findPageData();
      },
      findPageData() {
        this.loading = true
        let createDate = this.searchForm.createDate
        resourceApi.findEvaluatePage({
          pageSize: this.pageSize,
          pageIndex: this.pageIndex,
          name: this.searchForm.name,
          personnel: this.searchForm.personnel,
          beginDate: createDate ? createDate[0] : null,
          endDate: createDate ? createDate[1] : null
        }).then((res) => {
          this.loading = false
          if (res.data.messageCode === '200') {
            this.tableData = res.data.result.rows
            this.totalCount = res.data.result.totalCount
          } else {
            this.tableData = []
            this.totalCount = 0
          }
        })
      },
      addDialog() {
        this.getOne()
        this.formEdit = 'add'
        this.formTitle = '新增测定评价'
        this.dialogFormVisible = true
        this.isReady = true;
      },
      remove(row) {
        let tips = ''
        if (row) {
          tips = `此操作将删除: ${row.name}, 是否继续?`
        } else {
          return
        }
        this.$confirm(tips, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          resourceApi.deleteEvaluate(row.id).then((res) => {
            if (res.data.messageCode === '200') {
              this.$notify({
                title: '消息',
                message: ('删除成功！'),
                position: 'bottom-right',
                showClose: false,
                type: 'success'
              })
              this.findPageData()
            }
          })
        })
      },
      updateDialog(row) {
        this.formEdit = 'edit'
        this.formTitle = '修改测定评价'
        this.getInfo(row)
      },
      read(row) {
        this.disabled = true
        this.formEdit = 'read'
        this.formTitle = '查看测定评价'
        this.getInfo(row)
      },
      async getInfo(row) {
        this.getOne()

        let oneId = row.oneId
        if (oneId) {
          this.selectedOne(oneId);
        }
        let twoId = row.twoId
        if (twoId) {
          this.selectedTwo(twoId);
        }
        let threeId = row.threeId
        if (threeId) {
          this.selectedThree(threeId);
        }

        const res = await resourceApi.getEvaluateInfo(row.id)
        if (res.data.message === 'success') {
          let result = res.data.result
          this.addForm = result
          this.chilLon = this.addForm.lon;
          this.chilLat = this.addForm.lat;
          this.isReady = true
          if (result.germplasmType) {
            this.addForm.germplasmType = result.germplasmType.split(',')
          }
          this.dialogFormVisible = true
        }
      },
      validation() {
        let flag = true
        let message = null
        if (!this.addForm.name) {
          flag = false
          message = '请输入物种名称'
        }
        if (flag && !this.addForm.oneId) {
          flag = false
          message = '请选择保存库'
        }
        if (flag && !this.addForm.twoId) {
          flag = false
          message = '请选择保存区'
        }
        if (flag && !this.addForm.threeId) {
          flag = false
          message = '请选择隶属大类'
        }
        if (flag && !this.addForm.fourId) {
          flag = false
          message = '请选择小区'
        }
        if (!flag) {
          this.$message({
            message: message,
            type: 'warning'
          })
          return false
        }
        return true
      },
      saveData() {
        if (this.validation()) {
          this.showLoading()
          let params = Object.assign({}, this.addForm)
          params.germplasmType = this.addForm.germplasmType ? this.addForm.germplasmType.join(',') : null
          resourceApi.saveEvaluate(params).then((res) => {
            this.hideLoading()
            let message = this.formEdit === 'edit' ? '修改' : '保存'
            if (res.data.message === 'success') {
              this.$notify({
                title: '消息',
                message: (message + '成功！'),
                position: 'bottom-right',
                showClose: false,
                type: 'success'
              })
              this.cancel()
              this.findPageData()
            } else {
              this.$notify.error({
                title: '消息',
                message: message + '失败'
              })
            }
          })
        }
      },
      cancel() {
        this.addForm = {}
        this.disabled = false
        this.multipleSelection = []
        this.dialogFormVisible = false
      },
      cancelR() {
        this.pageIndexR = 1
        this.resourceCount = 0
        this.resourceTable = []
        this.dialogVisible = false
        this.isReady = false;
        this.$refs.lonRef.initData();
        this.$refs.latRef.initData();
      },
      getSpecies() {
        this.species = []
        this.speciesMap = {}
        resourceApi.findSpecies().then((res) => {
          let result = res.data.result
          if (res.data.message === 'success' && result) {
            this.species = result
            for (let i in result) {
              let item = result[i]
              this.$set(this.speciesMap, item.speciesName, item)
            }
          }
        })
      },
      speciesChange(value) {
        let name, species, family, purpose
        if (value) {
          let data = this.speciesMap[value]
          name = data.speciesName
          purpose = data.purpose
          let speciesLatin = data.latinName
          let familyName = data.familyName
          let familyLatin = data.familyLatinName
          species = name ? name + (speciesLatin ? '、' + speciesLatin : '') : ''
          family = familyName ? familyName + (familyLatin ? '、' + familyLatin : '') : ''
        }
        this.addForm.name = name
        this.addForm.specificName = species
        this.addForm.familyName = family
        this.$set(this.addForm, 'purpose', purpose)
      },
      numberClick() {
        if (!this.addForm.registerSaveId) {
          this.$message.warning('请先选择种质名称')
          return false
        }
        this.dialogVisible = true
        this.findResource()
      },
      findResource() {
        resourceApi.findResourcePage({
          registerSaveId: this.addForm.registerSaveId,
          pageSize: this.pageSizeR,
          pageIndex: this.pageIndexR
        }).then((res) => {
          let result = res.data.result
          if (res.data.messageCode === '200' && result) {
            let $this = this
            this.resourceTable = result.rows
            this.resourceCount = result.totalCount
            this.$nextTick(() => {
              let number = $this.addForm.resourceNumber ? $this.addForm.resourceNumber.split(',') : []
              if (number) {
                for (let i in number) {
                  $this.resourceTable.forEach(row => {
                    let obj = JSON.parse(row.dataJson)
                    row.zheight = obj['树高（m）']
                    row.dbh = obj['胸径（m）']
                    row.pew = obj['冠幅（m,东西）']
                    row.psn = obj['冠幅（m,南北）']

                    if (number[i] === row.number) {
                      $this.$refs.resourceTable.toggleRowSelection(row, true)
                    }
                  })
                }
              }
            })
          } else {
            this.resourceTable = []
            this.resourceCount = 0
          }
        })
      },
      getRegisterPreservation() {
        resourceApi.findRegisterPreservation({}).then((res) => {
          if (res.data.messageCode === '200' && res.data.result) {
            this.registerPreservation = res.data.result
          } else {
            this.registerPreservation = []
          }
        })
      },
      germplasmChange(value) {
        if (value) {
          this.addForm.registerSaveId = value
          resourceApi.getRegisterPreservationInfo(value).then((res) => {
            let result = res.data.result
            if (res.data.messageCode === '200' && result) {
              this.$set(this.addForm, 'germplasmName', result.name)
              this.$set(this.addForm, 'saveTime', result.saveTime)
              this.$set(this.addForm, 'lon', result.lon)
              this.$set(this.addForm, 'lat', result.lat)
              this.$set(this.addForm, 'alt', result.alt)
              if (result.type) {
                let type = result.type.split(',')
                this.$set(this.addForm, 'germplasmType', type)
              }
            }
          })
        } else {
          this.addForm.germplasmName = null
          this.addForm.saveTime = null
          this.addForm.germplasmType = null
          this.addForm.resourceNumber = null
          this.addForm.registerSaveId = null
        }
      },
      pager(val) {
        this.pageIndex = val
      },
      handleSizeChange(val) {
        this.pageSize = val
        this.tableData = []
        this.findPageData()
      },
      handleCurrentChange(val) {
        this.pageIndex = val
        this.tableData = []
        this.findPageData()
      },
      handleSizeChangeR(val) {
        this.pageSizeR = val
        this.resourceTable = []
        this.findResource()
      },
      handleCurrentChangeR(val) {
        this.pageIndexR = val
        this.resourceTable = []
        this.findResource()
      },
      handleSelection(selection, row) {
        let index = this.multipleSelection.indexOf(row.number)
        if (index < 0) {
          this.multipleSelection.push(row.number)
        } else {
          this.multipleSelection.splice(index, 1)
        }
      },
      handleSelectionAll(selection) {
        if (selection.length > 0) {
          selection.forEach((item) => {
            if (this.multipleSelection.indexOf(item.number) < 0) {
              this.multipleSelection.push(item.number)
            }
          })
        } else {
          this.resourceTable.forEach((item) => {
            this.multipleSelection.splice(this.multipleSelection.indexOf(item.number), 1)
          })
        }
      },
      getNumber() {
        let number = []
        this.multipleSelection.forEach(selion => {
          number.push(selion)
        })
        this.addForm.resourceNumber = number.join(',')
        this.cancelR()
      },
      getOne() {
        this.getModule('one').then(res => {
          this.oneData = res
        })
      },
      getTwo() {
        this.getModule('two').then(res => {
          this.twoData = res
        })
      },
      getThree() {
        this.getModule('three').then(res => {
          this.threeData = res
        })
      },
      getFour() {
        this.getModule('four').then(res => {
          this.fourData = res
        })
      },
      async getModule(module) {
        let result = []
        let res = await ResourceManageApi.getModule(module)
        if (res.data.message === 'success') {
          result = res.data.result
        }
        return result
      },
      async getChildren(data) {
        let result = []
        if (data) {
          let res = await ResourceManageApi.getChildren(data)
          if (res.data.message === 'success') {
            result = res.data.result
          }
        }
        return result
      },
      selectedOne(data) {
        this.twoData = []
        this.threeData = []
        this.fourData = []
        this.$set(this.addForm, 'twoId', null)
        this.$set(this.addForm, 'threeId', null)
        this.$set(this.addForm, 'fourId', null)
        if (data) {
          this.getChildren(data).then(res => {
            this.twoData = res
          })
        }
      },
      selectedTwo(data) {
        this.threeData = []
        this.fourData = []
        this.$set(this.addForm, 'threeId', null)
        this.$set(this.addForm, 'fourId', null)
        if (data) {
          this.getChildren(data).then(res => {
            this.threeData = res
          })
        }
      },
      selectedThree(data) {
        this.fourData = []
        this.$set(this.addForm, 'fourId', null)
        if (data) {
          this.getChildren(data).then(res => {
            this.fourData = res
          })
        }
      },
      showLoading() {
        this.$loading({
          lock: true,
          text: 'Loading',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        })
      },
      hideLoading() {
        this.$loading().close()
      },
      initBtn() {
        let permissionBtn = JSON.parse(localStorage.permissionBtn)
        this.addBtn = permissionBtn['evaluation_add']
        this.updateBtn = permissionBtn['evaluation_update']
        this.deleteBtn = permissionBtn['evaluation_delete']
      }
    }
  }
</script>
<style lang="less" scoped>
  .search {
    & /deep/ .el-form-item__label {
      font-size: 1.8rem;
    }
  }

  .el-dialog__body {
    .paging {
      padding: 0px;
      margin-bottom: 0px;
    }
  }
  /deep/ .el-dialog {
    min-width: 900px;
  }

  .form-table {
    width: 100%;

    table,
    tr,
    td {
      border: 1px solid #fff;
    }

    td {
      &:nth-child(even) {
        width: 32%;
      }

      &:nth-child(odd) {
        text-indent: 10px;
      }
    }

    /deep/ .el-input__inner {
      border: none;
    }
    /deep/ .el-textarea__inner {
      border: none;
    }

    .oblique {
      /deep/ .el-input__inner {
        font-style:oblique;
      }
    }
  }

  .el-form-item__label {
    padding: 0 20px 0 0 !important;
  }

  .content {
    margin-top: 10px;

    & /deep/ .el-checkbox__inner {
      height: 20px;
      width: 20px;
      font-size: 28px;
      font-weight: 400;
      color: rgba(255, 255, 255, 1);
      background: none;
    }

    & /deep/ .el-tooltip__popper {
      background-color: red;
    }

    & /deep/ .el-checkbox__inner::after {
      border-width: 2px;
      /* border-color: black; */
      height: 6px;
      left: 6px;
      top: 3px;
      width: 4px;
    }

    & /deep/ .el-checkbox__input.is-indeterminate .el-checkbox__inner::before {
      top: 8px;
      background: white;
    }
  }

  .line {
    display: inline-flex;
    height: 21px;
    width: 1px;
    background: rgba(0, 255, 255, 1);
    margin: 0 10px;
    vertical-align: middle;
  }

  .dialogBtn {
    font-size: 1.6rem;

    &:hover {
      background: rgba(12, 161, 151, 1);
    }
  }

  .coordinate {
    width: 25%;
  }
  .coordinate-type{
    width: 25%;
  }

  .td3-box {
    display: flex;
    justify-content: space-between;
    line-height: 45px;
    margin-left: 5px;
    margin-right: 5px;
  }
</style>
<style lang="less">
  /**
     * 修改样式   覆盖默认的饿了么全局样式
     */
  .el-form-item__label {
    padding: 0 20px 0 0 !important;
  }

</style>
